import axios from "axios";
import store from '../store/index';
import qs from 'qs';
let baseURL;
if(process.env.NODE_ENV === 'development') {
    baseURL = 'http://58.218.39.50:9002';
} else if(process.env.NODE_ENV === 'production') {
    baseURL = 'http://58.218.39.50:9002';
}
const http = axios.create({
  baseURL : baseURL,
  headers : {
  	"Content-Type" : "application/x-www-form-urlencoded;charset=UTF-8",
  	'Accept' : 'application/json'
  },
});
//添加请求拦截器
http.interceptors.request.use((config)=>{
    store.commit("setLoading",true);
    if (config.method == "post") {
      config.data = qs.stringify(config.data);
    }
    return config;
},(err)=>{
  alert("请求失败，请重试");
  store.commit("setLoading",false);
})
// 添加响应拦截器
http.interceptors.response.use(function (response) {
    store.commit("setLoading",false);
    return response;
}, function (error) {
    alert("请求失败，请重试");
    store.commit("setLoading",false);
    return Promise.reject(error);
});
export default http;
